home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / pdcurs21 / demos / firework.c next >
C/C++ Source or Header  |  1993-06-18  |  4KB  |  130 lines

  1. #include <stdio.h>
  2. #include <signal.h>
  3. #include <curses.h>
  4. #include <ctype.h>
  5. #include <sys/types.h>
  6. #include <time.h>
  7. #define DELAYSIZE 100
  8.  
  9. #ifdef PDCDEBUG
  10. char *rcsid_firework = "$Header: C:\CURSES\demos\RCS\firework.c 2.1 1993/06/18 20:24:05 MH Rel MH $";
  11. #endif
  12.  
  13. main()
  14. {
  15.        int start,end,row,diff,flag,direction,seed;
  16.        int myrefresh();
  17.        void explode();
  18.  
  19.        initscr();
  20.        if (has_colors())
  21.           start_color();
  22.        seed = time((time_t *)0);
  23.        srand(seed);
  24.        nodelay(stdscr,TRUE);
  25.        raw();
  26.        while(getch() == ERR)  /* loop until a key is hit */
  27.                {
  28.                 do {
  29.                        start = rand() % (COLS -3);
  30.                        end = rand() % (COLS - 3);
  31.                        start = (start < 2) ? 2 : start;
  32.                        end = (end < 2) ? 2 : end;
  33.                        direction = (start > end) ? -1 : 1;
  34.                        diff = abs(start-end);
  35.                    } while (diff<2 || diff>=LINES-2);
  36.                 attrset(A_NORMAL);
  37.                 for (row=0;row<diff;row++)
  38.                        {
  39.                         mvprintw(LINES - row,start + (row * direction),
  40.                                (direction < 0) ? "\\" : "/");
  41.                         if (flag++)
  42.                                {
  43.                                 myrefresh();
  44.                                 clear();
  45.                                 flag = 0;
  46.                                }
  47.                        }
  48.                if (flag++)
  49.                        {
  50.                         myrefresh();
  51.                         flag = 0;
  52.                        }
  53.                seed = time((time_t *)0);
  54.                srand(seed);
  55.                explode(LINES-row,start+(diff*direction));
  56.                clear();
  57.                myrefresh();
  58.               }
  59.        endwin();
  60.        exit(0);
  61. }
  62. void explode(row,col)
  63. int row,col;
  64. {
  65.        clear();
  66.        mvprintw(row,col,"-");
  67.        myrefresh();
  68.  
  69.        init_pair(1,get_colour(),COLOR_BLACK);
  70.        attrset(COLOR_PAIR(1));
  71.        mvprintw(row-1,col-1," - ");
  72.        mvprintw(row,col-1,"-+-");
  73.        mvprintw(row+1,col-1," - ");
  74.        myrefresh();
  75.  
  76.        init_pair(1,get_colour(),COLOR_BLACK);
  77.        attrset(COLOR_PAIR(1));
  78.        mvprintw(row-2,col-2," --- ");
  79.        mvprintw(row-1,col-2,"-+++-");
  80.        mvprintw(row,  col-2,"-+#+-");
  81.        mvprintw(row+1,col-2,"-+++-");
  82.        mvprintw(row+2,col-2," --- ");
  83.        myrefresh();
  84.  
  85.        init_pair(1,get_colour(),COLOR_BLACK);
  86.        attrset(COLOR_PAIR(1));
  87.        mvprintw(row-2,col-2," +++ ");
  88.        mvprintw(row-1,col-2,"++#++");
  89.        mvprintw(row,  col-2,"+# #+");
  90.        mvprintw(row+1,col-2,"++#++");
  91.        mvprintw(row+2,col-2," +++ ");
  92.        myrefresh();
  93.  
  94.        init_pair(1,get_colour(),COLOR_BLACK);
  95.        attrset(COLOR_PAIR(1));
  96.        mvprintw(row-2,col-2,"  #  ");
  97.        mvprintw(row-1,col-2,"## ##");
  98.        mvprintw(row,  col-2,"#   #");
  99.        mvprintw(row+1,col-2,"## ##");
  100.        mvprintw(row+2,col-2,"  #  ");
  101.        myrefresh();
  102.  
  103.        init_pair(1,get_colour(),COLOR_BLACK);
  104.        attrset(COLOR_PAIR(1));
  105.        mvprintw(row-2,col-2," # # ");
  106.        mvprintw(row-1,col-2,"#   #");
  107.        mvprintw(row,  col-2,"     ");
  108.        mvprintw(row+1,col-2,"#   #");
  109.        mvprintw(row+2,col-2," # # ");
  110.        myrefresh();
  111.        return;
  112. }
  113. int myrefresh()
  114. {
  115.        delay_output(DELAYSIZE);
  116.        move(LINES-1,COLS-1);
  117.        refresh();
  118. }
  119.  
  120. int get_colour()
  121. {
  122.  int attr;
  123.        attr = (rand() % 16)+1;
  124.        if (attr == 1 || attr == 9)
  125.           attr = COLOR_RED;
  126.        if (attr > 8)
  127.           attr |= A_BOLD;
  128.        return(attr);
  129. }
  130.